package com.od.controller;

import com.od.entity.Intention;
import com.od.service.IntentionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("intention")
@CrossOrigin
public class IntentionController {

    @Autowired
    private IntentionService intentionService;

    @RequestMapping("getIntentionById")
    @ResponseBody
    public List<Intention> getIntentionById(int intentionResume) {
        return intentionService.getIntentionById(intentionResume);
    }

    @RequestMapping("addIntention")
    @ResponseBody
    public int addIntention(@RequestBody Intention intention) {
        System.out.println(intention);
        return intentionService.addIntention(intention);
    }

    @RequestMapping("updateIntentionById")
    @ResponseBody
    public int updateIntentionById(@RequestBody Intention intention) {
        System.out.println(intention);
        return intentionService.updateIntentionById(intention);
    }

    @RequestMapping("deleteIntentionById")
    @ResponseBody
    public int deleteIntentionById(@RequestBody Map<String, Integer> intentionData) {
        int intentionId = (intentionData.get("intentionId"));
        return intentionService.deleteIntentionById(intentionId);
    }

}
